<template>
  <div class="my_item">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
    <van-checkbox-group v-model="checked" @change="chekChange">
      <div
        v-for="(item, index) in list"
        class="item"
        :class="proxy[status]"
        :style="plzr?'background-repeat: repeat-y;background-position-x: 30px;':''"
        :key="index"
      >
      <div v-if="plzr" style="display:flex">
        <van-checkbox :name="item.id" shape="square"></van-checkbox>
       </div>
       <!-- <div  class="item"   :class="proxy[status]"> -->
        <div class="item__left">
          <div class="item__left-top">
            <span class="top__unit">¥</span>
            <span class="top__price">{{ item.library.money }}</span>
          </div>
          <div class="item__left-bottom" v-if="item.good_id">指定商品使用</div>
          <div style="font-size:12px;color:#fff;margin-top:3vw">有效期</div>
          <div style="font-size:12px;color:#fff">{{ item.end_time }}</div>
        </div>
        <div class="item__right">
          <div class="item__right-top">
            <div class="top__title">{{ item.library.name}}</div>
            <div class="top__des"></div>
          </div>
          <!-- <div class="item__right-top">
            <div class="top__title" style="font-size:14px;color:#777777;height:16px">{{ item.remarks }}</div>
            <div class="top__des"></div>
          </div> -->
          <div class="item__right-top" >
            <span class="" v-if="item.status == 1" style="font-size:12px;color:#ccc">可转增数量：<span style="color:#FF8933">{{item.k_z_sum}}</span>张</span>
            <span class="" v-if="item.status == 1" style="font-size:12px;color:#ccc; margin-left:10px">已转增数量：{{item.y_z_sum}}张</span>
          </div>
          
          <div class="item__right-bottom">
            <!-- <span>有效期{{ item.end_time }}</span> -->
            <div
              class="transfer"
              @click="transfer(item)"
              v-if="item.k_z_sum>0&&!plzr&&item.status==1"
            >
              我要转赠
            </div>
            <div
              class="transfer"
              @click="topay(item)"
              v-if="item.k_z_sum>0&&!plzr&&item.status==1"
            >
              我要下单
            </div>
          </div>
        </div>
      <!-- </div> -->
      </div>
    </van-checkbox-group>
    </van-list>
    <!-- <div>
      <div class="plzr"  v-if="!plzr&&status==1" @click="operation">批量转让</div>
      <div class="czqr" v-if="plzr">
        <div style="flex:1;justify-content: center;background-color: #C1C1C1; height: 50px;align-items: center;display: flex;" @click="close">取消</div>
        <div style="flex:1;justify-content: center;background-color: #F86831; height: 50px;align-items: center;display: flex;" @click="confirm">确认批量转让</div>
      </div>
    </div> -->
  </div>
  
</template>
<script>
import { codeLists } from "@/api/myExaminatonGaper.js";
import {myCouponLists, myCouponLists2,couponIncrease}  from '@/api/api'
import moment from "moment";
import {Toast} from "vant";
import { createApp } from 'vue';
import { Checkbox, CheckboxGroup } from 'vant';
import { ref } from 'vue';

export default {
  props: {
    status: {
      type: Number,
    },
  },
  data() {
    return {
      plzr:false,
      showConfirm:false,
      checked:[],
      loading: false,
      finished: false,
      list: [{
        good_id:"1",
        library:{
          name:"测试mode",
          money:"20"
        },
        end_time:"2022-09-11",
        status:"1",

      }, {
        good_id:"2",
        library:{
          name:"测试mode",
          money:"20"
        },
        end_time:"2022-09-11",
        status:"1",
      }
    ],
      proxy: {
        1: "canUse",
        2: "used",
        3: "outLimit",
      },
      pageInfo: {
        offset: 1,
      }
    };
  },
  components: {},
  methods: {
    // 下单
    topay(data){
      // Toast('暂未实现');
      console.log(data);
      this.$router.push({name:'everyMonth5', params:{exchange_library_id :data.library_id,couponId:data.id}})
    },
    chekChange(){
      console.log(this.checked);
    },
    setup() {
      const checked = ref(['a', 'b']);
      return { checked };
    },
    operation(){
      this.plzr=true;
    },
    close(){
      this.plzr=false;
    },
    async transfer(item) {
      // console.log(item)
      this.$router.push(`/MyTransfer/${item.library_id}`);
    },
    confirm(){
      console.log(this.checked.toString());
      if(this.checked.length==0){
        Toast('未选中');
        return;
      }
      this.$router.push(`/MyTransfer/${this.checked.toString()}`);
    },
    async onLoad() {
      const res = await myCouponLists2({
        status: this.status,
        offset: this.pageInfo.offset,
        limit: 10
      });
      console.log(res)
      this.loading = false;
      const arr = res.data.data.map((ele) => ({
        ...ele,
        end_time: moment(ele.end_time).format("YYYY-MM-DD"),
      }));
      if (this.pageInfo.offset == 1) {
        this.list = [...arr];
      } else {
        this.list = [...this.list, ...arr];
      }
      this.pageInfo.offset++;
      if (arr.length < 10) {
        this.finished = true;
      }
    },
  },
};
</script>
<style>
 body{
    background-color: #F5F5F5!important;
  }
</style>
<style scoped>
 
.my_item {
  margin: 0 auto;
  width:93.6vw;
  padding-top: 4vw;
  height: 100vh;
}
.item {
  width: 93.6vw;
  height: 29.3vw;
  background-size: cover;
  margin-bottom: 4vw;
  display: flex;
}
.item.canUse {
  background-image: url("~@/assets/canUse.png");
}
.check {
  background-repeat: repeat-y;
  background-position-x: 30px;
}
.item.used {
  background-image: url("~@/assets/used.png");
}
.item.outLimit {
  background-image: url("~@/assets/outLimitTime.png");
}
.item__left {
  width: 29.3vw;
  height: 29.3vw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.item__left-top {
}
.top__unit {
  font-size: 4.5vw;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #ffffff;
}
.top__price {
  /*48px*/
  font-size: 6.4vw;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #ffffff;
  margin-top: 2.6vw;
}
.item__left-bottom {
  font-size: 3.2vw;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
}
.item__right {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-top: 1vw;
  padding-left: 3.2vw;
  padding-bottom: 4.53vw;
}
.item__right-bottom {
  margin-top: 2vw;
  font-size: 3.2vw;
  /* display: flex; */
  /* justify-content: space-between; */
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #a1a1a1;
  /* align-items: center; */
}
.top__title {
  font-size: 15px;
  height: 45px;
  width:55vw;
  overflow:hidden;
  /* white-space: nowrap; */
  text-overflow: ellipsis;
  -o-text-overflow:ellipsis;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #333333;
}
.top__des {
  margin-top: 2.1vw;
  font-size: 3.3vw;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #777777;
}
.transfer {
  width: 18.1vw;
  height: 5vw;
  border-radius: 2.9vw;
  text-align: center;
  line-height: 5vw;
  border: 2px solid #ff8933;
  font-size: 3.2vw;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ff8933;
  float: right;
  margin-right: 10px;
}
.plzr{
  height: 50px;
    background: #FF8933;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}
.czqr{
    height: 50px;
    /* background: #FF8933;
    border-radius: 4px; */
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    right: 0;
    width: 100%;
    position: fixed;
    bottom: 0px;
}
.van-icon {
  border-radius: 5px!important;
}
</style>
